<?php
class BcsController extends AppController {

	var $name = 'Bcs';

	function index($idct) {
		$this->Cookie->write('idct',$idct);

		$this->Bc->recursive = 0;
		$this->set('bcs', $this->paginate('Bc',array('Bc.ctrinh_id'=>$idct)));
		$this->set(compact('idct'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid bc', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('bc', $this->Bc->read(null, $id));
	}

	function add() {
		$idct=$this->Cookie->read('idct');
		if (!empty($this->data)) {
			$this->Bc->create();
			$this->data ['Bc'] ['ctrinh_id']=$idct;
			if ($this->Bc->save($this->data)) {
				$this->Session->setFlash(__('The bc has been saved', true));
				$this->redirect(array('action' => 'index',$idct));
			} else {
				$this->Session->setFlash(__('The bc could not be saved. Please, try again.', true));
			}
		}
		$this->set(compact('ctrinhs','idct'));
	}

	function edit($id = null) {
		$idct=$this->Cookie->read('idct');
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid bc', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			$this->data ['Bc'] ['ctrinh_id']=$idct;
			if ($this->Bc->save($this->data)) {
				$this->Session->setFlash(__('The bc has been saved', true));
				$this->redirect(array('action' => 'index',$idct));
			} else {
				$this->Session->setFlash(__('The bc could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Bc->read(null, $id);
		}
		
		$this->set(compact('ctrinhs','idct'));
	}

	function delete($id = null) {
		$idct=$this->Cookie->read('idct');
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for bc', true));
			$this->redirect(array('action'=>'index',$idct));
		}
		if ($this->Bc->delete($id)) {
			$this->Session->setFlash(__('Bc deleted', true));
			$this->redirect(array('action'=>'index',$idct));
		}
		$this->Session->setFlash(__('Bc was not deleted', true));
		$this->redirect(array('action' => 'index',$idct));
	}
}
